package ru.ifmo.swing.genetics.monitoring.string;

import org.uncommons.watchmaker.framework.PopulationData;
import ru.ifmo.automaton.Automaton;
import ru.ifmo.common.Source;
import ru.ifmo.genetics.automaton.synchronizeable.fitness.StandartFitness;
import ru.ifmo.swing.genetics.monitoring.common.AbstractChartDataProvider;

/**
 * @author avhaliullin
 */
public class DeficiencyProvider extends AbstractChartDataProvider<String> {
    private final Source<Automaton<Character, String>> automatonSource;

    public DeficiencyProvider(String name, Source<Automaton<Character, String>> automatonSource) {
        super(name);
        this.automatonSource = automatonSource;
    }

    public double getValue(PopulationData<? extends String> populationData) {
        return StandartFitness.df(automatonSource.create(), populationData.getBestCandidate());
    }
}
